//根据localStorage里的值绑定当前默认样式
window.GLOBAL = window.G = {};
var getTheme = function() {
	var theme = eval(window.localStorage["themecolor"]) || "default";
	return theme;
};
seajs.config({
	/* 默认路径前缀 */
	paths : {
		
	},
	base: "/business/",
	alias : {
		// url配置信息
		"urlconfig" : "urlcofig/config",
		// 全局工具, global.js加载的时候同时加载
		"globalutil" : "js/common/util/src/js/globalutil",
		//core核心组件
		'$' : 'js/core/jquery/src/jquerycmd-1.10.1',
		'jquery' : 'js/core/jquery/src/jquerycmd-1.10.1',
		'jquery-migrate' : 'js/core/jquery/src/jquery-migratecmd.min',
		
		'class' : 'js/core/class/src/class',
		'aspect' : 'js/core/base/src/aspect',
		'events' : 'js/core/event/src/events',
		'base' : 'js/core/base/src/base',
		'widget' : 'js/core/widget/src/widget',// 组件核心
		'autoRender' : 'js/core/widget/src/autoRender',// 自动加载组件
		'handlebars' : 'js/core/handlebars/src/handlebars',// 模板解析
		"cookie" : "js/core/cookie/jquery.cookie-1.4.1.min.js",

		/* common组件 */
		"wizard" : "js/common/wizard/js/wizardBS", // 向导
		"tabs" : "js/common/tabs/src/js/tabs",    // 页签
		"header" : "js/common/header/src/js/header", //主页头部	
		"table" : "js/common/table/src/js/table", // 表格公共组件	
		"index" : "js/common/index/src/js/index",			// 索引页
		"menu" : "js/common/menu/src/js/menu",				// 菜单
		"gallery" : "js/common/gallery/src/js/gallery",				// gakkery
		
		
		"form" : "js/common/form/src/js/form",  //常规表单
		"form_multiblock" : "js/common/form/src/js/form_multiblock",  //分块表单

		
		"console":"js/common/console/src/js/console",	// 控制台
		"consoledata":"js/common/console/src/js/consoledata",	// 控制台界面数据
		
		
		
		"dialogform_tree":"js/common/warehouse/src/js/dialogform_tree",	// 商家树

		'cityselector' : 'js/common/cityselector/js/cityselector',
		'modaldialog' : 'js/common/dialog/src/js/modaldialog',
		
		'timefilter' : 'js/common/timefilter/src/js/timefilter', // 时间选择按钮组
		'daterangeinput' : 'js/common/timefilter/src/js/daterangeinput', // 时间范围选择输入框
		
		'queryparamutil' : 'js/common/util/src/js/queryparamutil', // 查询参数构造工具
		'numberutil' : 'js/common/util/src/js/numberutil', // 数字工具
		'validationutil' : 'js/common/util/src/js/validationutil', // 校验工具
		
		// admin管理
		'recharge':'js/common/admin/src/js/recharge', //充值
		'carrier':'js/common/admin/src/js/carrier',	// 运营商管理
		'carrieradmin':'js/common/admin/src/js/carrieradmin',	// 运营商管理员
		'carrierlicense':'js/common/admin/src/js/carrierlicense',	// 运营商授权
		'storelicenselist':'js/common/admin/src/js/storelicenselist',	// 运营商授权
		'licensecarrier':'js/common/admin/src/js/licensecarrier',	// 运营商license
		'licensestore':'js/common/admin/src/js/licensestore',	// 商家license
		"loader":"js/common/admin/src/js/loader/loader",	// 阻止按钮重复提交组件
		"coltogather":"js/common/coltogather/coltogather",	// 合并单元格
		"carrierlicenseauditing":"js/common/admin/src/js/carrierlicenseauditing",	//
		"carrierlicenseretauditing" : "js/common/admin/src/js/carrierlicenseretauditing.js",
		"carrierauditing" : "js/common/admin/src/js/carrierauditing.js",//企业审批列表
    "rechargeauditing" : "js/common/admin/src/js/rechargeauditing.js",//话费充值审批列表
		//isv管理
		"isv":"js/common/isv/src/js/isv",//ISV管理维护
		"isvadmin":"js/common/isv/src/js/isvadmin",//ISV管理员维护
		//isv详情
		'isvdetail':'js/common/isv/src/js/isvdetail',	// isv详情
		'isvadmindetail':'js/common/isv/src/js/isvadmindetail',//isvadmin详情
		
		// 详情组件
		'userdetail':'js/common/admin/src/js/userdetail',	// 用户详情
		'carrierdetail':'js/common/admin/src/js/carrierdetail',	// 企业详情
		'carrierlicensedetail':'js/common/admin/src/js/carrierlicensedetail',	// 企业充值退订详情
		
		// tool工具
		'shopcarttool':'js/common/shopcart/src/js/shopcarttool',	// 购物车存储工具
		"onhandlocalstore" : "js/common/onhandgoods/src/js/onhandlocalstore", // 期初库存缓存
		"orderstoretool" : "js/common/productlist/src/js/orderstoretool", // 订单存储工具
		"productdetailtools" : "js/common/productdetail/src/js/productdetailtools", // 订单存储工具
		
		"datatableutil" : 'js/common/table/src/js/datatableutil',
		'ajaxReloadDataTable' : 'js/common/table/src/js/ajaxReloadDataTable',
		
		//common组件实例
		"indexheader" : "js/common/header/src/js/indexheader", //主页头部-经销商门户
		"menubar" : "js/common/menu/src/js/menubar",				// 菜单
		"menulist" : "js/common/menu/src/js/menulist",				// 菜单
		
		//tree公共组件
		"dialog_dynatree_common": "js/tool/dynatree/dialog_dynatree_common",
		//ztree组件
		"zTreeStyle.css":'js/tool/ztree/zTreeStyle.css',
	    "ztreeCore":'js/tool/ztree/ztree.core',
	    "ztreeExcheck":'js/tool/ztree/ztree.excheck',
		
		
		// 基础档案
		"basearchive-form":"js/common/basearchive/src/js/basearchive-form",
		"basearchive-table":"js/common/basearchive/src/js/basearchive-table",
		"basearchive-util":"js/common/basearchive/src/js/basearchive-util",
		"dialog_select_customer":"js/common/finance/src/js/receipt/dialog_select_customer", // 选择客户对话框
		"dialog_select_supplier":"js/common/finance/src/js/payment/dialog_select_store", // 选择供应商对话框
		
		// 商品分类树维护
		'form_goodstypemaintain' : 'js/common/product/src/js/form_goodstypemaintain',
		'goodstype_edit' : 'js/common/product/src/js/goodstype_edit',
		
		// 商家维护
		'store_form' : 'js/common/basearchive/ins/store/store_form',
		
		//权限管理组件
		"form_pwdmodify":"js/common/pub/src/js/form_pwmodify",  //修改密码页面
		"user" : "js/common/pub/src/js/user", // 用户列表组件
		"role" : "js/common/rbac/src/js/role", // 角色列表组件
		"form_roleadd" : "js/common/rbac/src/js/form_roleadd",
		"userofrole":"js/common/rbac/src/js/userofrole",
		"roleuser":"js/common/rbac/src/js/roleuser",
		"form_rolemodify" : "js/common/rbac/src/js/form_rolemodify",
		"functionrole" : "js/common/rbac/src/js/functionrole",
		"rolefunction" : "js/common/rbac/src/js/rolefunction",
		"menuform_tree" : "js/common/rbac/src/js/menuform_tree",
		"functionAuthorizeTorole" : "js/common/rbac/src/js/functionAuthorizeTorole",
		"adminuser" : "js/common/rbac/src/js/adminuser",
		"adminuseraddform" : "js/common/rbac/src/js/adminuseraddform",
		"multiselect2side":"js/common/multiselect2side/multiselect2side",
		"dialogmultiselect2side":"js/common/multiselect2side/dialogmultiselect2side",
		"applytype":"js/common/pub/src/js/applytype",//应用分类维护
		"applytypeadd":"js/common/pub/src/js/applytypeadd",//应用分类增加
		"applytypemodify":"js/common/pub/src/js/applytypemodify",//应用分类修改
		"apply":"js/common/pub/src/js/apply",//应用维护
		"applyadd":"js/common/pub/src/js/applyadd",//应用增加
		"applymodify":"js/common/pub/src/js/applymodify",//应用修改
		"applyuser":"js/common/pub/src/js/applyuser",//用户应用状态控制
		
		"subcompany":"js/common/pub/src/js/subcompany",//分公司维护
		"subcompanyadd":"js/common/pub/src/js/subcompanyadd",//分公司新建
		"subcompanymodify":"js/common/pub/src/js/subcompanymodify",//分公司修改
		
		//用户维护部分
		"rolemaintain" : "js/common/rbac/src/js/rolemaintain",
		"rolemaintain_add" : "js/common/rbac/src/js/rolemaintain_add",
		"rolemaintain_modify" : "js/common/rbac/src/js/rolemaintain_modify",
		
		// bootstrap css
		'bootstrap.css' : 'css/tool/bootstrap/bootstrap.css',
		'bootstrap-responsive.css' : 'css/tool/bootstrap/bootstrap-responsive.css',
		'light-theme.css' : 'css/tool/bootstrap/light-theme.css',
		'dark-theme.css' : 'css/tool/bootstrap/dark-theme.css',
		'dark-blue-theme.css' : 'css/tool/bootstrap/dark-blue-theme.css',
		'theme-colors.css': 'css/tool/bootstrap/theme-colors.css',
		'jquery.multiselect2side.css':'css/tool/select2/jquery.multiselect2side.css',
		
		//插件css
		'wizard.css' : 'css/tool/fuelux/wizard.css',
		'fuelux.min.css' : 'css/tool/fuelux/fuelux.min.css',
		'bootstrap-datetimepicker.min.css' : 'css/tool/bootstrap_datetimepicker/bootstrap-datetimepicker.min.css',
		'bootstrap-dynatree.css' : 'css/tool/dynatree/ui.dynatree.css',
		'select2.css' : 'css/tool/select2/select2_3.4.6.css',
		'daterangepicker.css' : 'css/tool/bootstrap_daterangepicker/daterangepicker-bs2.css',
		'bootbox.css' : 'css/tool/bootbox/bootbox.css',
		'bootstrap-editable.css' : 'css/tool/xeditable/bootstrap-editable.css',
		'css.css' : 'css/apply/css.css',
		
		//bootstrap 核心js
		'bootstrap_commonrequire' : 'js/tool/bootstrap/bootstrap_commonrequire',
		'bootstrap' : 'js/tool/bootstrap/bootstrapcmd',
		'bootstrap_nav' : 'js/tool/bootstrap/navcmd',
		'bootstrap_theme':'js/tool/bootstrap/themecmd',
		
		//插件js
		'bootstrap-daterangepicker' : 'js/tool/bootstrap_daterangepicker/bootstrap-daterangepickercmd',
		'bootstrap_datetimepicker':'js/tool/bootstrap_datetimepicker/bootstrap-datetimepickercmd',
		'bootstrap_datetimepicker.zh-CN':'js/tool/bootstrap_datetimepicker/locales/bootstrap-datetimepickercmd.zh-CN',
		'bootstrap_maxlength':'js/tool/bootstrap_maxlength/bootstrap-maxlengthcmd.min',
		
		//tool组件
		'bootbox' : 'js/tool/bootbox/bootboxcmd',
		'layout' : 'js/tool/layout/src/js/layout',
		'store' : 'js/tool/store/storecmd',
		'json' : 'js/tool/store/jsoncmd',
		'jsuri' : 'js/tool/jsuri/Uricmd',
		'moment' : 'js/tool/moment/momentcmd',
		"draganddrop":"js/tool/draganddrop/src/js/draganddrop",//新的拖拽接口
		'autosize':'js/tool/autosize/jquery.autosizecmd.min',
		'charCount':'js/tool/charCount/charCountcmd',
		'jquery.dataTables': 'js/tool/datatables/jquery.dataTablescmd.min',
		'jquery-ui': 'js/tool/jquery_ui/jquery-uicmd.min',
		"jquery.ui.sortable" : "js/tool/jquery.ui.sortable/src/js/jquery.ui.sortable",
		'jquery.validate': 'js/tool/validate/jquery.validatecmd',
		'jquery.dynatree' : 'js/tool/dynatree/jquery.dynatreecmd',
		'fuelux_wizard' : 'js/tool/fuelux/wizardcmd',
		'fuelux_wizard2' : 'js/tool/fuelux/wizard2cmd',
		'select2' : 'js/tool/select2/select2_3.4.6',
		"jquery.multiselect2side":"js/common/select/jquery.multiselect2side",
		'imagezoom':'js/tool/imagezoom/imagezoomcmd',
		
		//fileupload
		'fileupload':'js/tool/jquery-file-upload/js/jquery.fileupload',
		'fileupload-process':'js/tool/jquery-file-upload/js/jquery.fileupload-process',
		'fileupload-image':'js/tool/jquery-file-upload/js/jquery.fileupload-image',
		'fileupload-audio':'js/tool/jquery-file-upload/js/jquery.fileupload-audio',
		'fileupload-video':'js/tool/jquery-file-upload/js/jquery.fileupload-video',
		'fileupload-validate':'js/tool/jquery-file-upload/js/jquery.fileupload-validate',
		'fileupload-ui':'js/tool/jquery-file-upload/js/jquery.fileupload-ui',
		'jquery-iframe-transport':'js/tool/jquery-file-upload/js/jquery.iframe-transport',
		'jquery-form':'js/tool/jquery-file-upload/jquery.formcmd',
		
		'tmpl':'js/tool/jquery-file-upload/tmpl',
		'load-image' : 'js/tool/jquery-file-upload/load-imagecmd.min',
		//fileupoad-css
		'fileupload-css':'css/tool/jquery-file-upload/jquery.fileupload.css',
		'fileupload-ui-css':'css/tool/jquery-file-upload/jquery.fileupload-ui.css',
		//fileupload-common-main
		'fileupload-main':'js/tool/jquery-file-upload/fileupload_main',
		
		'jquery-ui-widget':'js/tool/jquery-file-upload/jquery.ui.widget',
		
		'ueditor.config':'js/tool/ueditor/ueditor.config',
		'ueditor.all':'js/tool/ueditor/ueditor.all',
		'ueditor-patch-149':'js/tool/ueditor/ueditor-patch-149',
		'ueditor-zh-cn':'js/tool/ueditor/lang/zh-cn/zh-cn',
		
		 //图表工具
		'highcharts':'js/tool/highcharts/highcharts',
		'highcharts.exporting':'js/tool/highcharts/exporting',
		
		 // 文件上传
		'fileinput':'js/tool/bootstrap_fileinput/fileinput.min',
		'fileinput_locale_zh.min':'js/tool/bootstrap_fileinput/fileinput_locale_zh',
		'fileinput.min.css':'css/tool/bootstrap_fileinput/fileinput.min.css',
		'fileinput.css':'css/tool/bootstrap_fileinput/fileinput.css',
		
		
		
		
		//editor
		
	},

	
	// 移除shim插件 seajs2.1.0推荐
	plugins : [ 'text' ],
	debug : true,
	
	charset : 'utf-8',
	editable : true
});
// url配置
seajs.use("urlconfig");

seajs.use("globalutil");

/**
 * 重新登录
 */
function oauth2Relogin() {
	/*jQuery.removeCookie("at", {path: '/'});
	//刷新
	window.location.reload();*/
  window.location.href = "/index.html";
}

seajs.use([ "jquery", "cookie" ], function(jQuery, cookie) {
	var $ = jQuery;
	// 全局ajax配置，配置IE下缓存问题，OAuth2.0方案
	jQuery.ajaxSetup({
		// 解决IE下ajax请求使用缓存问题
		cache : false,
		//添加OAuth2.0 认证头
		beforeSend: function( xhr ) {
			//保存access_token的cookie名称与com.yonyou.mcloud.security.oauth2.client.CASWebClientFilter中的accessTokenCookieName参数要一致
			var accessToken = $.cookie("at");
			if (accessToken != undefined) {
				var authorization = 'OAuth2 ' + accessToken;
				//设置认证信息
				xhr.setRequestHeader('Authorization', authorization);
				
			} else {
				//如果启用了access_token失效时自动重新登录的功能
				if (this.oauth2ReloginIfAccessTokenExpired) {
					//刷新
					//oauth2Relogin();
				}
			}
		  },
		statusCode : {
			//注意OAuth2.0错误都是http status code为400的错误！而且返回格式都是JSON格式
			400:function( /*jqXHR*/ jqXHR, /*String*/ textStatus, /*String*/ errorThrown) {
				if (jqXHR.responseJSON != null) {
					//如果启用了access_token失效时自动重新登录的功能
					if (this.oauth2ReloginIfAccessTokenExpired) {
						//8193错误：access_token未找到
						//8211错误：access_token无效，可能已过期，需要重新授权
						if (jqXHR.responseJSON.error_code == 8211|| jqXHR.responseJSON.error_code == 8193) {
							oauth2Relogin();
							return;
						}
					}
					//定义了OAuth2.0失败时的回调函数
					if (this.oauth2Fail != null) {
						this.oauth2Fail(jqXHR.responseJSON);
					}
				}
			}
		},
		oauth2Fail: function(data) {
			alert("服务器返回OAuth2.0错误（"+data.error+"）\n错误代码："+data.error_code+"\n错误信息："+data.error_description+"\n错误URI："+data.error_uri);
		},
		//当access_token失效时重新登录
		oauth2ReloginIfAccessTokenExpired: true
	});
});
